package com.malred.tool.mytools.myqr.common;

import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author malguy-wang sir
 * @create ---
 */
public class commonQR {
    /**
     * 直接输入网址创建二维码
     * @param URL 输入网址时加上http或https才能扫出来网页,否则只是字符串
     * @return
     * @throws Exception
     */
    public String crate(String URL)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            Process pr = rt.exec("myqr "+URL);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * @param URL 网址
     * @param edge 边长参数
     * @return
     * @throws Exception
     */
    public String crate(String URL,int edge)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            Process pr = rt.exec("myqr "+URL+" -v "+edge);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * @param URL 网址(带http)
     * @param name 生成图片名称(带后缀)
     * @return
     * @throws Exception
     */
    public String crate(String URL,String name)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            Process pr = rt.exec("myqr "+URL+" -n "+name);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * @param URL 网址
     * @param edge 边长
     * @param name 名称
     * @return
     * @throws Exception
     */
    public String crate(String URL,int edge,String name)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            if(edge>40) edge=40;
            if(edge<1) edge=1;
            Process pr = rt.exec("myqr "+URL+" -v "+edge+" -n "+name);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
    /**
     *
     * @param URL 网址
     * @param edge 边长
     * @param name 名称
     * @param path 保存地址
     * @return
     * @throws Exception
     */
    public String crate(String URL,int edge,String name,String path)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            if(edge>40) edge=40;
            if(edge<1) edge=1;
            Process pr = rt.exec("myqr "+URL+" -v "+edge+" -n "+name+" -d "+path);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
    public String crate(String URL,String name,String path)throws Exception{
        try {
            Runtime rt = Runtime.getRuntime();
            Process pr = rt.exec("myqr "+URL+" -n "+name+" -d "+path);
//            Process pr = rt.exec("D:/APP/Evernote/Evernote.exe");//open evernote program
//                Process pr = rt.exec("D:/APP/Tim/Bin/QQScLauncher.exe");//open tim program
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"GBK"));
            String line = null;
            while ((line = input.readLine())!=null){
                System.out.println(line);
            }
            int exitValue = pr.waitFor();
            System.out.println("Exited with error code "+exitValue);
            return line;
        } catch (IOException e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return null;
        }
    }
//    public static void main(String[] args) throws Exception{
//        commonQR commonQR = new commonQR();
//        System.out.println(commonQR.crate("https://cn.bing.com/","必应.jpg","C:\\Users\\13695\\Desktop\\有用的网页\\myqr制作二维码\\"));
//    }
}
